using System;
using Habanero.Base;
using Habanero.Base.Exceptions;

namespace FireStarterModeller.BO
{
    public class DMRelationshipDeleteActionRule : IBusinessObjectRule
    {
        private DMRelationship _dmRelationship;

//        public DMRelationshipDeleteActionRule(DMRelationship dmRelationship)
//        {
//            if (dmRelationship == null) throw new ArgumentNullException("dmRelationship");
//            _dmRelationship = dmRelationship;
//        }

        public bool IsValid()
        {
            throw new HabaneroApplicationException("The IsValid is no longer Valid you should use the IsValid(bo) method");
        }

        public bool IsValid(IBusinessObject bo)
        {
            _dmRelationship = (DMRelationship) bo;
            return
                !(_dmRelationship.DeleteAction == DeleteParentAction.DereferenceRelated &&
                  _dmRelationship.RelationshipType == RelationshipType.Composition);
        }

        public string Name
        {
            get { return "DMRelationshipDeleteActionRule"; }
        }

        public string Message
        {
            get
            {
                return "The Delete Action on Relationship '" + _dmRelationship + "'"
                       + " on the class '" + _dmRelationship.ClassDM + "'"
                       + " cannot be Dereference Related because the Relationship Type is Composition.";
            }
        }

        public ErrorLevel ErrorLevel
        {
            get { return ErrorLevel.Error; }
        }
    }
}